import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/login/index.vue"
import Main from "@/views/home/Main.vue";


Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

const routes = [
	{
		path: '/',
		name: 'home',
		redirect: "/login"
	},
	{
		path: "/login",
		name: "Login",
		component: Login
	},
	{
		path: "/main",
		name: "Main",
		component: () => import("@/views/home/Home.vue"),
		redirect: '/welcome',
		children: [
			{
				path: '/welcome',
				component: Main
			},
			{
				path: "/main",
				component: () => import("@/views/home/Main.vue")
			},
			{
				path: "/system/user",
				component: () => import("@/views/home/system/User.vue")
			},
			{
				path: "/system/dept",
				component: () => import("@/views/home/system/Dept.vue")
			},
			{
				path: "/system/ins_fee",
				component: () => import("@/views/home/system/InsFee.vue")
			},
			{
				path: "/system/menu",
				component: () => import("@/views/home/system/Menu.vue")
			},
			{
				path: "/system/role",
				component: () => import("@/views/home/system/Role.vue")
			},
			{
				path: "/system/dict",
				component: () => import("@/views/home/system/Dict.vue")
			},
			{
				path: "/dict/data/:dictId",
				component: () => import("@/views/home/system/Data.vue")
			},
			{
				path: "/system/notice",
				component: () => import("@/views/home/system/Notice.vue")
			},

			//============================药品进销存============================
			//厂家信息维护
			{
				path: "/stock/producter",
				name: "Producter",
				component: () => import("@/views/home/erp/producter/index.vue")
			},
			//药品信息维护
			{
				path: "/stock/medicinal",
				name: "medicines",
				component: () => import("@/views/home/erp/medicines/index.vue")
			},
			//供应商维护
			{
				path: "/stock/provider",
				name: "Provider",
				component: () => import("@/views/home/erp/provider/index.vue")
			},
			//采购入库
			{
				path: "/stock/purchase",
				name: "Purchase",
				component: () => import("@/views/home/erp/purchase/index.vue")
			},
			//采购入库/新增采购
			{
				path: "/erp/purchase/newPurchase",
				name: "NewPurchase",
				component: () => import("@/views/home/erp/purchase/newPurchase.vue")
			},
			//采购入库/订单查询
			{
				path: "/erp/purchase/editPurchase/:purchaseId",
				name: "EditPurchase",
				component: () => import("@/views/home/erp/purchase/editPurchase.vue")
			},
			//入库审核
			{
				path: "/stock/examine",
				name: "Examine",
				component: () => import("@/views/home/erp/purchase/auditList.vue")
			},
			//库存查询
			{
				path: "/stock/inventory",
				name: "Inventory",
				component: () => import("@/views/home/erp/inventoryLog/index.vue")
			},
			//============================药品进销存============================


			//===============================统计===============================
			//收支统计
			{
				path: "/statistics/revenue",
				name: "Revenue",
				component: () => import("@/views/home/statisics/revenue/index.vue")
			},
			//药品销售统计
			{
				path: "/statistics/sales",
				name: "Sales",
				component: () => import("@/views/home/statisics/drug/index.vue")
			},
			//检查项目统计
			{
				path: "/statistics/check",
				name: "Check",
				component: () => import("@/views/home/statisics/check/index.vue")
			},
			//工作量统计
			{
				path: "/statistics/workload",
				name: "Workload",
				component: () => import("@/views/home/statisics/workload/index.vue")
			},
			//医生评价
			{
				path:"/statistics/comment",
				name:"Comment",
				component:()=> import("@/views/home/statisics/comment/index.vue")
			},
			//===============================统计===============================

			{
				path: "/doctor/scheduling",
				name: "schedule",
				component: () => import("@/views/home/docter/Schedule.vue")
			},
			{
				path: "/doctor/patient",
				name: "Patient",
				component: () => import("@/views/home/docter/Patient.vue")
			},
			{
				path: "/doctor/carelist",
				name: "Carelist",
				component: () => import("@/views/home/docter/Carelist.vue")
			},
			{
				path: "/doctor/myscheduling",
				name: "Myscheduling",
				component: () => import("@/views/home/docter/Myscheduling.vue")
			},
			{
				path: "/doctor/registered",
				name: "Registered",
				component: () => import("@/views/home/docter/Registered.vue")
			},
			{
				path: "/doctor/registeredlist",
				name: "RegisteredList",
				component: () => import("@/views/home/docter/RegisteredList.vue")
			},
			{
				path: "/doctor/newcare",
				name: "Newcare",
				component: () => import("@/views/home/docter/Newcare.vue")
			},
			{
				path: '/charge/docharge',
				component: () => import('@/views/home/charge/charge.vue'),
				// name: '/charge/docharge',
				meta: {title: '处方收费', icon: 'list'}
			},
			{
				path: '/charge/chargelist',
				component: () => import('@/views/home/charge/chargelist.vue'),
				// name: '/charge/chargelist',
				meta: {title: '收费查询', icon: 'list'}
			},
			{
				path: '/charge/backfee',
				component: () => import('@/views/home/charge/backfee.vue'),
				// name: '/charge/backfee',
				meta: {title: '处方退费', icon: 'list'}
			},
			{
				path: '/charge/backfeelist',
				component: () => import('@/views/home/charge/backfeelist.vue'),
				// name: '/charge/backfeelist',
				meta: {title: '退费查询', icon: 'list'}
			},
			{
				path: '/charge/dispensing',
				component: () => import('@/views/home/charge/index.vue'),
				// name: '/charge/dispensing',
				meta: {title: '处方发药', icon: 'list'}
			},
			{
				path: '/check/docheck',
				component: () => import('@/views/home/checkResult/newcheck.vue'),
				// name: '/check/docheck',
				meta: {title: '新开检查', icon: 'list'}
			},
			{
				path: '/check/checkresult',
				component: () => import('@/views/home/checkResult/checking.vue'),
				// name: '/check/checkresult',
				meta: {title: '检查结果录入', icon: 'list'}
			},
			{
				path: '/check/checklist',
				component: () => import('@/views/home/checkResult/checklist.vue'),
				// name: '/check/checklist',
				meta: {title: '检查结果查询', icon: 'list'}
			}
			,
			{
				path: '/system/news',
				component: () => import('@/views/home/system/News.vue'),
				// name: '/check/checklist',
				meta: {title: '新闻列表', icon: 'list'}
			}
		]
	},
	{
		path: '/',
		name: 'home',
		redirect: "/login"
	},
	{
		path: "/login",
		name: "Login",
		component: Login
	},
	{
		path: "/main",
		name: "Main",
		component: () => import("@/views/home/Home.vue"),
		children: [
			{
				path: "/system/user",
				component: () => import("@/views/home/system/User.vue")
			},
			{
				path: "/system/dept",
				component: () => import("@/views/home/system/Dept.vue")
			},
			{
				path: "/system/ins_fee",
				component: () => import("@/views/home/system/InsFee.vue")
			},
			{
				path: "/system/menu",
				component: () => import("@/views/home/system/Menu.vue")
			},
			{
				path: "/system/role",
				component: () => import("@/views/home/system/Role.vue")
			},
			{
				path: "/system/dict",
				component: () => import("@/views/home/system/Dict.vue")
			},
			{
				path: "/system/notice",
				component: () => import("@/views/home/system/Notice.vue")
			},
			{
				path: "/system/reg_fee",
				component: () => import("@/views/home/system/RegFee.vue")
			},
			{
				path: "/system/log_login",
				component: () => import("@/views/home/system/LoginInfo.vue")
			},
			{
				path: "/system/log_opt",
				component: () => import("@/views/home/system/OperLog.vue")
			},
			{
				path:"/system/userInfo",
				component:()=> import("@/views/home/system/UserInfo.vue")
			},
			{
				path: "/stock/medicinal",
				name: "medicines",
				component: () => import("@/views/home/erp/medicines/index.vue")
			},
			{
				path: "/stock/producter",
				name: "Producter",
				component: () => import("@/views/home/erp/producter/index.vue")
			},
			{
				path: "/stock/provider",
				name: "Provider",
				component: () => import("@/views/home/erp/provider/index.vue")
			},
			{
				path: "/doctor/scheduling",
				name: "schedule",
				component: () => import("@/views/home/docter/Schedule.vue")
			},
			{
				path: "/doctor/patient",
				name: "Patient",
				component: () => import("@/views/home/docter/Patient.vue")
			},
			{
				path: "/doctor/carelist",
				name: "Carelist",
				component: () => import("@/views/home/docter/Carelist.vue")
			},
			{
				path: "/doctor/myscheduling",
				name: "Myscheduling",
				component: () => import("@/views/home/docter/Myscheduling.vue")
			},
			{
				path: "/doctor/registered",
				name: "Registered",
				component: () => import("@/views/home/docter/Registered.vue")
			},
			{
				path: "/doctor/registeredlist",
				name: "RegisteredList",
				component: () => import("@/views/home/docter/RegisteredList.vue")
			},
			{
				path: "/doctor/newcare",
				name: "Newcare",
				component: () => import("@/views/home/docter/Newcare.vue")
			},
			{
				path: '/charge/docharge',
				component: () => import('@/views/home/charge/charge.vue'),
				// name: '/charge/docharge',
				meta: {title: '处方收费', icon: 'list'}
			},
			{
				path: '/charge/chargelist',
				component: () => import('@/views/home/charge/chargelist.vue'),
				// name: '/charge/chargelist',
				meta: {title: '收费查询', icon: 'list'}
			}
			
		]
	},

]


const router = new VueRouter({
	routes
})

router.beforeEach((to, from, next) => {
	let path = to.path;
	if (path === "/" || path === "/login") {
		next();
	} else {
		let token = sessionStorage.getItem("token");
		if (token) {
			next();
		} else {
			next("/login");
		}
	}
})

export default router
